<template>
  <div class="index">
    <van-nav-bar :title="subject_name" left-text="返回" left-arrow @click-left="onClickLeft" />
    <div class="tops">
      <p></p>
      <p>{{ rki }}</p>
    </div>

    <div>
      <van-cell-group :title="'人数:' + dataList.length" border>
        <van-cell :value="data.scroe + '分'" v-for="(data, index) in dataList" :key="index" center border>
          <!-- 使用 title 插槽来自定义标题 -->
          <template #title>
            <div class="box1">
              <div class="box2">
                <span>{{ index + 1 }}</span>
                <van-image :src="data.img" style="width: 50%" />
              </div>
              <div class="box3">
                <span>{{ data.username }} </span>
                <span>{{ data.id_card }} </span>
              </div>
            </div>
          </template>
        </van-cell>
      </van-cell-group>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
import { NavBar, Toast } from 'vant'
import { Cell, CellGroup } from 'vant'

export default {
  name: 'ranking',
  data() {
    return {
      dataList: [{}],
      rkname: '',
      rki: 0,
      subject_name: '',
      colors: ''
    }
  },
  methods: {
    onClickLeft() {
      // Toast('返回');
      this.$router.push('/sroucxq')
    },
    onrk() {
      for (let i = 0; i < this.dataList.length; i++) {
        if (this.dataList[i].id_card == this.rkname) {
          this.rki = '第' + (i + 1) + '名'
        }
      }
      if (this.rki == 0) {
        this.rki = '未上榜'
      }
    }
  },
  mounted() {
    axios({
      method: 'post',
      url: this.baseURL + '/api/api/ranking',
      data: {
        id: localStorage.getItem('showSorce_id')
        // exam_paper: localStorage.getItem('major_id')
      }
    }).then((res) => {
      // console.log(res)
      if (res.data.code == 0) {
        Toast(res.data.msg)
      } else {
        this.dataList = res.data
        // console.log(this.dataList)
        this.rkname = localStorage.getItem('id_card')
        this.subject_name = localStorage.getItem('subject_name')
        this.onrk()
      }
    })
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.index {
  /* background-image: url('../assets/tu2.jpg'); */
  width: 100%;
  height: 100%;
  position: fixed;
  background-size: 100% 100%;
}
.tops {
  width: 100%;
  height: 15%;
  background-color: rgb(71, 159, 241);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 26px;
  color: white;
}
.box1 {
  display: flex;
}
.box2 {
  display: flex;
  /* width: 100%; */
  width: 80px;
  align-items: center;
  font-size: 12px;
  justify-content: space-around;
}
</style>
